"""
应用数据模式
"""
from datetime import datetime
from typing import Optional, Dict, Any, List
from pydantic import BaseModel


class ApplicationBase(BaseModel):
    """应用基础模式"""
    name: str
    description: Optional[str] = None
    app_type: str  # docker, k8s, static
    repository_url: Optional[str] = None
    dockerfile_path: Optional[str] = None
    build_command: Optional[str] = None
    start_command: Optional[str] = None
    health_check_url: Optional[str] = None
    health_check_interval: int = 30
    health_check_timeout: int = 10
    health_check_retries: int = 3
    environment_variables: Optional[Dict[str, str]] = None
    resource_limits: Optional[Dict[str, Any]] = None
    ports: Optional[List[Dict[str, Any]]] = None
    volumes: Optional[List[Dict[str, Any]]] = None
    networks: Optional[List[Dict[str, Any]]] = None
    labels: Optional[Dict[str, str]] = None


class ApplicationCreate(ApplicationBase):
    """创建应用模式"""
    pass


class ApplicationUpdate(BaseModel):
    """更新应用模式"""
    description: Optional[str] = None
    repository_url: Optional[str] = None
    dockerfile_path: Optional[str] = None
    build_command: Optional[str] = None
    start_command: Optional[str] = None
    health_check_url: Optional[str] = None
    health_check_interval: Optional[int] = None
    health_check_timeout: Optional[int] = None
    health_check_retries: Optional[int] = None
    environment_variables: Optional[Dict[str, str]] = None
    resource_limits: Optional[Dict[str, Any]] = None
    ports: Optional[List[Dict[str, Any]]] = None
    volumes: Optional[List[Dict[str, Any]]] = None
    networks: Optional[List[Dict[str, Any]]] = None
    labels: Optional[Dict[str, str]] = None
    is_active: Optional[bool] = None


class Application(ApplicationBase):
    """应用响应模式"""
    id: int
    is_active: bool
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True
